#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Database initialization script
"""

import sys
from pathlib import Path

# Add project root to Python path
project_root = Path(__file__).parent.absolute()
sys.path.insert(0, str(project_root))

def init_database():
    """Initialize database tables"""
    try:
        from backend.config.database import Base, engine
        
        print("🗄️  正在初始化数据库表...")
        
        # Create all tables
        Base.metadata.create_all(bind=engine)
        
        print("✅ 数据库表创建成功!")
        
        # Show created tables
        from sqlalchemy import inspect
        inspector = inspect(engine)
        tables = inspector.get_table_names()
        
        print(f"📋 已创建的表: {', '.join(tables)}")
        
    except Exception as e:
        print(f"❌ 数据库初始化失败: {e}")
        sys.exit(1)

if __name__ == "__main__":
    init_database()